// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <nebula/types/meta/binary_type.h>

namespace nebula {


    /// \brief Concrete type class for fixed-size binary data
    class TURBO_EXPORT FixedSizeBinaryType : public FixedWidthType, public ParametricType {
    public:
        static constexpr Type::type type_id = Type::FIXED_SIZE_BINARY;
        static constexpr bool is_utf8 = false;

        static constexpr const char *type_name() { return "fixed_size_binary"; }

        explicit FixedSizeBinaryType(int32_t byte_width)
                : FixedWidthType(Type::FIXED_SIZE_BINARY), byte_width_(byte_width) {}

        explicit FixedSizeBinaryType(int32_t byte_width, Type::type override_type_id)
                : FixedWidthType(override_type_id), byte_width_(byte_width) {}

        std::string to_string(bool show_metadata = false) const override;

        std::string name() const override { return "fixed_size_binary"; }

        DataTypeLayout layout() const override {
            return DataTypeLayout(
                    {DataTypeLayout::Bitmap(), DataTypeLayout::FixedWidth(byte_width())});
        }

        int byte_width() const override { return byte_width_; }

        int bit_width() const override;

        // Validating constructor
        static turbo::Result<std::shared_ptr<DataType>> create(int32_t byte_width);

    protected:
        std::string compute_fingerprint() const override;

        int32_t byte_width_;
    };
}  // namespace nebula
